import request from "@/utils/request";

// 获取所有平台属性列表        attrInfoList       GET     /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
// 保存平台属性(新增和更新)    saveAttrInfo       POST    /admin/product/saveAttrInfo
// 删除平台属性               deleteAttr         DELETE  /admin/product/deleteAttr/{attrId}
// 根据属性id获取属性详情      getAttrValueList   GET     /admin/product/getAttrValueList/{attrId}
export interface AttrValueModel {
  valueName: string;
  id?: number;
  attrId?: number;
  inputVisible?: boolean;
}

export interface AttrModel {
  id?: number;
  attrName: string; // 属性名
  attrValueList: AttrValueModel[]; // 表格中添加的属性值列表
  categoryId: number | undefined; // 三级分类的id(不是二级,不是一级)
  categoryLevel: number; // 第几级分类,写死是 3
}

export default {
  //获取到平台属性列表的请求
  getAttrInfoList(
    category1Id: number,
    category2Id: number,
    category3Id: number
  ) {
    return request.get<any, AttrModel[]>(
      `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
    );
  },
  //保存平台属性(添加和修改用的同一个接口)
  save(data: AttrModel) {
    return request.post<any, null>(`/admin/product/saveAttrInfo`, data);
  },
  //根据id删除品台数据
  delete(attrId: number) {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
  },
};
